﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

using transportsystem.DTO;
using UTIL;


namespace transportsystem.DAO
{
    public class HangDAO
    {
        public static DataTable getHangByMaDatVe(int maDatVe)
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_TraCuuHangTheoMaDatVe";
            SqlParameter[] sp = new SqlParameter[1];
            sp[0] = new SqlParameter("@madatve", maDatVe);
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName, sp);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }
        public static DataTable layDanhSachHangTheoMaKhoHang(int ma)
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_TraCuuHangTheoMa";
            SqlParameter[] sp = new SqlParameter[1];
            sp[0] = new SqlParameter("@makho", ma);
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName, sp);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }
        public static bool capNhatHang(Hang h)
        {
            SqlCommand cmd = SqlDataAccessHelper.CreateCommand("sp_ThemHang");
            cmd.Parameters.Add("@mahang", SqlDbType.Int).Value = h.Mahang;
            cmd.Parameters.Add("@tenhang", SqlDbType.NVarChar).Value = h.Tenhang;
            cmd.Parameters.Add("@nguoigui", SqlDbType.NVarChar).Value = h.Nguoigui;
            cmd.Parameters.Add("@nguoinhan", SqlDbType.NVarChar).Value = h.Nguoinhan;
            cmd.Parameters.Add("@sodt", SqlDbType.NVarChar).Value = h.Sodt;
            cmd.Parameters.Add("@ngaygui", SqlDbType.DateTime).Value = h.Ngaygui;
            cmd.Parameters.Add("@makho", SqlDbType.Int).Value = h.Makho;
            cmd.Parameters.Add("@soluong", SqlDbType.Int).Value = h.Soluong;
            cmd.Parameters.Add("@trongluong", SqlDbType.Float).Value = h.Trongluong;
            return SqlDataAccessHelper.ExecCmd(cmd);
        }

        public static bool xoaHang(Hang h)
        {
            SqlCommand cmd = SqlDataAccessHelper.CreateCommand("sp_XoaHang");
            cmd.Parameters.Add("@mahang", SqlDbType.Int).Value = h.Mahang;
            return SqlDataAccessHelper.ExecCmd(cmd);
        }

        public static DataTable timKiemHangTheoTen(string ten)
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_TraCuuHangTheoTen";
            SqlParameter[] sp = new SqlParameter[1];
            sp[0] = new SqlParameter("@tenhang", ten);
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName, sp);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }
    }
}
